package com.sinoglobal.sinostore;


import com.lidroid.xutils.util.LogUtils;
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.cache.memory.impl.WeakMemoryCache;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import com.nostra13.universalimageloader.core.download.BaseImageDownloader;
import com.sinoglobal.sinostore.system.Constants;

import android.content.Context;

public class SinoStore {
	public static int WIDTHPIXELS;// 屏幕宽度
	public static int HEIGHTPIXELS;// 屏幕高度
	public static Context context;
	
	/**
	 * 
	 * @author lk
	 * @createdate 2015-3-20 下午5:12:00
	 * @Description: (初始化商城信息)
	 * @param context
	 * @param userId
	 * @param userName
	 * @param nickName
	 * @param score
	 *
	 */
	public static void init(Context context,String userId,String userCenterId,String userName,String nickName,String score){
		SinoStore.context = context;
		Constants.userId = userId;
		Constants.userCenterId = userCenterId;
		Constants.userName = userName;
		Constants.nickName = nickName;
		Constants.score = score;
		Constants.STOREFLAG = context.getString(R.string.STOREFLAG);
		getDisplayMetrics();
		initImageLoader(context);
		//Log开关设置
		LogUtils.allowD = false;
		LogUtils.allowE = false;
		LogUtils.allowI = false;
		LogUtils.allowV = false;
		LogUtils.allowW = false;
	}
	
	
	/**初始化图片加载类配置信息**/
	private static void initImageLoader(Context context) {
		// This configuration tuning is custom. You can tune every option, you
		// may tune some of them,
		// or you can create default configuration by
		// ImageLoaderConfiguration.createDefault(this);
		// method.
		ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
				.memoryCacheExtraOptions(480, 800)
				// max width, max height，即保存的每个缓存文件的最大长宽
				.threadPoolSize(3)
				// 线程池内加载的数量
				.threadPriority(Thread.NORM_PRIORITY - 2).denyCacheImageMultipleSizesInMemory().memoryCache(new WeakMemoryCache())
				.memoryCacheSize((int) (2 * 1024 * 1024)).memoryCacheSizePercentage(13)
				.diskCacheFileNameGenerator(new Md5FileNameGenerator()).diskCacheSize(50 * 1024 * 1024) // 50
				// Mb
				.tasksProcessingOrder(QueueProcessingType.LIFO).imageDownloader(new BaseImageDownloader(context, 5 * 1000, 30 * 1000)) // connectTimeout
				.writeDebugLogs() // Remove for release app
				.build();

		ImageLoader.getInstance().init(config);// 全局初始化此配置
	}
	/**
	 * 
	 * @author LK
	 * @createdate 2015-3-24 上午11:03:38
	 * @Description: (初始化数据)
	 * @param userCenterId
	 * @param userName
	 * @param nickName
	 * @param score
	 *
	 */
	public static void initData(String userId,String userCenterId,String userName,String nickName,String score){
		Constants.userId = userId;
		Constants.userCenterId = userCenterId;
		Constants.userName = userName;
		Constants.nickName = nickName;
		Constants.score = score;
	}
	
	public static void initScore(String score){
		Constants.score = score;
	}
	/**
	 * 
	* @author LK
	* @methods getDisplayMetrics 
	* @description 描述信息 获取屏幕宽度高度
	* @date 2015-1-12 下午7:33:26 参数说明
	 */
	private static void getDisplayMetrics(){
		WIDTHPIXELS = context.getResources().getDisplayMetrics().widthPixels;
		HEIGHTPIXELS = context.getResources().getDisplayMetrics().heightPixels;
	}

}
